﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnliAttributeDrawer : PropertyDrawer {
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        string value="";
        //Debug.Log(property.propertyType);
        //Debug.Log(property.type);
        //Debug.Log(property.name);
        //Debug.Log();

        switch (property.propertyType)
        {
            case SerializedPropertyType.Integer:
                value = property.intValue.ToString();
                break;
            case SerializedPropertyType.Boolean:
                value = property.boolValue.ToString();
                break;
            case SerializedPropertyType.Float:
                value = property.floatValue.ToString();
                break;
            case SerializedPropertyType.String:
                value = property.stringValue;
                break;
            case SerializedPropertyType.Color:
                value = property.colorValue.ToString();
                break;
            case SerializedPropertyType.ObjectReference:
                //利用反射来获取类的属性，并只读显示
               // value = SerialObj(property);
                break;
            case SerializedPropertyType.LayerMask:
                break;
            case SerializedPropertyType.Enum:
                value = property.enumNames[property.enumValueIndex];
                break;
            case SerializedPropertyType.Vector2:
                value = property.vector2Value.ToString();
                break;
            case SerializedPropertyType.Vector3:
                value = property.vector3Value.ToString();
                break;
            case SerializedPropertyType.Vector4:
                value = property.vector4Value.ToString();
                break;
            case SerializedPropertyType.Rect:
                value = property.rectValue.ToString();
                break;
            case SerializedPropertyType.ArraySize:
                break;
            case SerializedPropertyType.Character:
                break;
            case SerializedPropertyType.AnimationCurve:
                break;
            case SerializedPropertyType.Bounds:
                break;
            case SerializedPropertyType.Gradient:
                break;
            case SerializedPropertyType.Quaternion:
                break;
            case SerializedPropertyType.ExposedReference:
                break;
            case SerializedPropertyType.FixedBufferSize:
                break;
            default:
                break;
        }
        EditorGUI.LabelField(position, property.name + "\t\t:\t" + value);

    }


    
    private string SerialObj(SerializedProperty property)
    {
        string result = "";
        Object obj = property.objectReferenceValue;
        var type = obj.GetType();
       /* switch (type.Name)
        {
            default:
                break;
        }

        FieldInfo[] fields= type.GetFields();
        foreach (var i in fields)
        {
            
        }*/
        return result;
    }
}
